home *** CD-ROM | disk | FTP | other *** search
- /* chsize.c, from page 352 of Turbo C Bible */
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- main ()
- {
- int filehandle, answer = 0;
- char filename [80];
- printf ("Enter name of file to truncate: ");
- gets (filename);
- if ((filehandle = open (filename, O_RDWR)) == -1)
- {
- perror ("open failed");
- exit (1);
- }
- /* Now give user a warning and a chance to abort */
- while (answer != 'N' && answer != 'Y')
- {
- printf ("Truncate %s to size zero? (Y or N)",
- filename);
- scanf (" %1s", &answer);
- answer = toupper (answer);
- }
- if (answer == 'Y')
- {
- if (chsize (filehandle, 0L) == -1)
- {
- perror ("chsize failed");
- }
- else
- {
- printf ("%s successfully truncated.\n", filename);
- }
- }
- }